package com.zzl.boot.bigevent.controller;

import com.aliyuncs.exceptions.ClientException;
import com.zzl.boot.bigevent.pojo.result;
import com.zzl.boot.bigevent.utils.AliOss;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

@RestController
public class fileUploadController {

    @PostMapping("/upload")
    public result<String> upload(MultipartFile file) throws IOException, ClientException {
        String filename = file.getOriginalFilename();
        String suffix = filename.substring(filename.lastIndexOf("."));//获得文件后缀
        String name = UUID.randomUUID().toString()+suffix;//拼接uuid组成随机文件名
        String imgUrl= AliOss.uploadFile(name,file.getInputStream());
        //file.transferTo(new File("C:\\Users\\15392907328\\Desktop\\bigEvent\\"+name));
        return result.success(imgUrl);
    }
}
